<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>北京航天公司固定资产管理系统</title>
</head>
<body>
<form action="javascript:void(0)" class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">所属组织</label>
        <div class="layui-input-inline">
            <select name="home_organ" lay-filter="mySelect">
                <option value="">请选择所属组织</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属部门</label>
        <div class="layui-input-inline">
            <select name="depa" lay-filter="mySelects">
                <option value="">请选择部门</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">借用责任人</label>
        <div class="layui-input-inline">
            <input type="text" name="admin" placeholder="请输入借用责任人" lay-verify="title" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">预计归还日期</label>
        <div class="layui-input-inline">
            <input type="text" name="return_time" id="appDate" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">借用物品</label>
        <div class="layui-input-block" id="propertyDiv">

        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">申请说明</label>
        <div class="layui-input-block">
            <textarea name="purpose" class="layui-textarea"></textarea>
        </div>
    </div>
</form>
<button onclick="submit()" class="layui-btn">提交</button>
</body>
</html>
<script type="text/javascript"  src="/js/jquery-1.8.2.js"></script>
<script type="text/javascript"  src="/layui/layui.all.js" ></script>
<link rel="stylesheet" href="/layui/css/layui.css">
<script type="text/javascript">
    var form=layui.form;
    $(function () {
        layui.use(['form', 'layedit', 'laydate'], function() {
            var layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;
        })
        form.render();

            //初始化  时间控件
            var laydate=layui.laydate;
            laydate.render({
                elem: '#appDate', //指定元素
                type:'date',
            })

        InitProv();

        //监控lay-filter=
        //
        //
        // 的下拉框事件
        form.on('select(mySelect)',function(object){
            // $("select[name='fen_did']").eq(1).empty()
            $.post('/borrow/getDepaId?id='+object.value,function (res) {
                for (var i = 0; i < res.length; i++) {
                    $("select[name='depa']").append('<option value="'+res[i].did+'">'+res[i].dname+'</option>')
                }
                form.render();
            },"json")
        })

        //监控lay-filter=mySelects
        form.on('select(mySelects)',function(object){
            var id = $("select[name='depa']").val()
            $("#propertyDiv").empty();
            $.post('/borrow/getProperty?property_dep_id='+id,function (res) {
                console.log(res)
                for (var i in res) {
                    $("#propertyDiv").append("<input type='checkbox' name='property_id' id='property_id'  value='"+res[i].property_id+"' title='"+res[i].property_name+"'>");
                }
                form.render();
            },"json")
        })



    })
    function InitProv() {
        $.post("/borrow/getDepaId?id=0",function (res) {
            for (var i = 0; i <res.length ; i++) {
                $("select[name='home_organ']").append("<option value='"+res[i].did+"'>"+res[i].dname+"</option>");
            }
            form.render();
        },"json")
    }

    function submit(){
        var dataForm = $("form").serialize();
        $.post("/borrow/getAddBorrow?"+dataForm,function (res) {
            // console.log(res)
            if(res == 1){
                layer.alert("申请成功")
                setTimeout(function () {
                    location.href="/jump/goBorrowIndex";
                },2000)
            } else {
                alert("添加失败！！！")
            }
        },"json")
    }
</script>